﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Csla;

namespace Asah.SiteWorx.ProductCatalog
{
    [Serializable()]
    public class ProductInfo : Csla.ReadOnlyBase<ProductInfo>
    {
        private int _id;
        private string _title;
        private string _description;
        private string _itemNumber;
        private string _dimensions;
        private decimal _unitPrice;
        private string _imagePath;
        private int _position;
        private Membership.User _createdBy;
        private SmartDate _createdDate;
        private Membership.User _lastUpdatedBy;
        private SmartDate _lastUpdatedDate;

        public int ID
        {
            get
            {
                return _id;
            }
            internal set
            {
                _id = value;
            }
        }

        public string Title
        {
            get
            {
                return _title;
            }
            internal set
            {
                _title = value;
            }
        }

        public string Description
        {
            get
            {
                return _description;
            }
            internal set
            {
                _description = value;
            }
        }

        public string ItemNumber
        {
            get
            {
                return _itemNumber;
            }
            internal set
            {
                _itemNumber = value;
            }
        }

        public string Dimensions
        {
            get
            {
                return _dimensions;
            }
            internal set
            {
                _dimensions = value;
            }
        }

        public decimal UnitPrice
        {
            get
            {
                return _unitPrice;
            }
        }

        public string ImagePath
        {
            get
            {
                return _imagePath;
            }
            internal set
            {
                _imagePath = value;
            }
        }

        public int Position
        {
            get
            {
                return _position;
            }
            internal set
            {
                _position = value;
            }
        }

        public Membership.User CreatedBy
        {
            get
            {
               return _createdBy;
            }
        }

        public string CreatedDate
        {
            get
            {
                return _createdDate.ToString("g");
            }
            internal set
            {
                _createdDate.Text = value;
            }
        }

        public Membership.User LastUpdatedBy
        {
            get
            {
                return _lastUpdatedBy;
            }
        }

        public string LastUpdatedDate
        {
            get
            {
                return _lastUpdatedDate.ToString("g");
            }
            internal set
            {
                _lastUpdatedDate.Text = value;
            }
        }

        public override string ToString()
        {
            return _title;
        }

        protected override object GetIdValue()
        {
            return _title;
        }

        private ProductInfo()
        {
            // require use of factory methods
        }

        internal ProductInfo(int id, string title, string description, string itemNumber, string dimensions,  decimal unitPrice, 
                             string imagePath, int position, Guid createdBy, SmartDate createdDate, Guid lastUpdatedBy, 
                             SmartDate lastUpdatedDate)
        {
            _id = id;
            _title = title;
            _description = description;
            _itemNumber = itemNumber;
            _dimensions = dimensions;
            _unitPrice = unitPrice;
            _imagePath = imagePath;
            _position = position;
            _createdBy = Membership.User.GetUser(createdBy);
            _createdDate = createdDate;
            _lastUpdatedBy = Membership.User.GetUser(lastUpdatedBy);
            _lastUpdatedDate = lastUpdatedDate;
        }
    }
}
